package com.ruoyi.web.controller.fire;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fire.domain.FireAlarm;
import com.ruoyi.fire.service.IFireAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报警信息Controller
 * 
 * @author wswxyw
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/fire/alarm")
public class FireAlarmController extends BaseController
{
    @Autowired
    private IFireAlarmService fireAlarmService;

    /**
     * 查询报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('fire:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(FireAlarm fireAlarm)
    {
        startPage();
        List<FireAlarm> list = fireAlarmService.selectFireAlarmList(fireAlarm);
        return getDataTable(list);
    }

    /**
     * 导出报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('fire:alarm:export')")
    @Log(title = "报警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FireAlarm fireAlarm)
    {
        List<FireAlarm> list = fireAlarmService.selectFireAlarmList(fireAlarm);
        ExcelUtil<FireAlarm> util = new ExcelUtil<FireAlarm>(FireAlarm.class);
        util.exportExcel(response, list, "报警信息数据");
    }

    /**
     * 获取报警信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:alarm:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return success(fireAlarmService.selectFireAlarmByUId(uId));
    }

    /**
     * 新增报警信息
     */
    @PreAuthorize("@ss.hasPermi('fire:alarm:add')")
    @Log(title = "报警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FireAlarm fireAlarm)
    {
        return toAjax(fireAlarmService.insertFireAlarm(fireAlarm));
    }

    /**
     * 修改报警信息
     */
    @PreAuthorize("@ss.hasPermi('fire:alarm:edit')")
    @Log(title = "报警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FireAlarm fireAlarm)
    {
        return toAjax(fireAlarmService.updateFireAlarm(fireAlarm));
    }

    /**
     * 删除报警信息
     */
    @PreAuthorize("@ss.hasPermi('fire:alarm:remove')")
    @Log(title = "报警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(fireAlarmService.deleteFireAlarmByUIds(uIds));
    }
}
